/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

(function(){
	'use strict';

	var player = null,
    canvas = wx.createCanvasContext('firstCanvas'),
		// playbtn = document.getElementById('play'),
		seeker = "50%",
    rate = "50%",
    volume = "50%",
    manifest = "http://wxzb.b-bri.cn/munankeji/test.m3u8";

	function playpause(){
		player[(player.paused)?'play':'pause']();
	}

	function init(){
		player = new HLSPlayer(canvas, manifest.value);
		// playbtn.removeEventListener('click', init, false);
		player.addEventListener('ready', function(){
			// playbtn.textContent = "Play";
			// playbtn.addEventListener('click', playpause, false);

			seeker.max = player.duration;
			seeker.addEventListener('change', function(){
				player.currentTime = seeker.value;
			}, false);

			rate.addEventListener('change', function(){
				player.playbackRate = rate.value;
			}, false);

			volume.addEventListener('change', function(){
				player.volume = volume.value;
			}, false);
		}, false);
		player.addEventListener('timeupdate',function(){
			seeker.value = player.currentTime;
		}, false);
		// player.addEventListener('play', function(){ playbtn.textContent = "Pause"; }, false);
		// player.addEventListener('pause', function(){ playbtn.textContent = "Play"; }, false);
		player.addEventListener('ended', function(){
			// playbtn.textContent = "Play";
			player.currentTime = 0;
		}, false);
	}

	// playbtn.addEventListener('click', init, false);

})();